#  -*- coding:utf-8 -*-
import json

def get_stored_username ():
    """ 如果用户名存在，就获取它 """

    source_name = './read_file/user.json'
    try:
        with open(source_name) as f_obj:
            user_name = json.load(f_obj)
    except FileNotFoundError:
        return None

    else:
        return user_name

def get_new_username ():
    """ 如果没有用户名， 则让用户输入用户名"""
    user_name = input("What's you name ? ")
    file_name = './read_file/user.json'
    with open(file_name, 'w') as f_obj:
        json.dump(user_name, f_obj)
    return user_name

def greet_user ():
    """ 问候用户， 并指出其名字 """
    user_name = get_stored_username()
    if user_name:
        print("Welcome back, " + user_name + " !!")

    else:

        user_name = get_new_username()
        print("We'll rememeber you when you come back, " + user_name + " !!!")